package com.glsc.ngateway.platform.controller.cmdb;

import cn.hutool.core.util.StrUtil;
import com.glsc.ngateway.common.api.common.enums.DictConstant;
import com.glsc.ngateway.common.base.domain.mysql.cmdb.CmdbDict;
import com.glsc.ngateway.common.base.domain.mysql.cmdb.CmdbDictValue;
import com.glsc.ngateway.common.api.common.utils.PageUtil;
import com.glsc.ngateway.platform.service.cmdb.CmdbDictService;
import com.glsc.ngateway.platform.service.cmdb.CmdbDictValueService;
import com.glsc.ngateway.platform.utils.JsonTool;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.*;
import java.util.stream.Collectors;

/**
 * 字典项接口
 */
@RestController
@RequestMapping("api/dict")
@Api(value = "字典项controller", tags = {"字典项接口"})
public class DictController {

    private static Logger logger = LoggerFactory.getLogger(DictController.class);

    @Resource
    private CmdbDictService cmdbDictService;

    @Resource
    private CmdbDictValueService cmdbDictValueService;

//    @Resource
//    private RoleAllowProcessTypeService roleAllowProcessTypeService;

    @PostMapping("/update")
//    @RequiredPermission("/api/dict/update")
    @ApiOperation(value = "更新字典项信息", notes = "更新字典项信息")
    public Map<String, Object> updateDict(@RequestBody CmdbDict dict, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<>();

        String dictName = dict.getDictName();
        if (null == dictName || (null != dictName && dictName.length() == 0)) {
            result.put("status", -1);
            result.put("message", "字典项名称不可以为空");
            return result;
        }
        CmdbDict checkTag1 = cmdbDictService.findByName(dictName);
        if (null != checkTag1 && !checkTag1.getDictId().equals(dict.getDictId())) {
            result.put("status", -1);
            result.put("message", "字典项名称已存在，不可以重复");
            return result;
        }
        String dictCode = dict.getDictCode();
        if (null != dictCode) {
            CmdbDict checkTag2 = cmdbDictService.findByDictCode(dictCode);
            if (null != checkTag2 && !checkTag2.getDictId().equals(dict.getDictId())) {
                result.put("status", -1);
                result.put("message", "字典项名称已存在，不可以重复");
                return result;
            }
        }

        try {
            List<CmdbDictValue> dvs = new ArrayList<>();
            List<CmdbDictValue> dictValues = dict.getDictValues();
            if (null != dictValues && dictValues.size() > 0) {
                for (CmdbDictValue dictValue : dictValues) {
                    CmdbDictValue dv = cmdbDictValueService.saveDictValue(dictValue);
                    dvs.add(dv);
                }
                dict.setDictValues(dvs);
            }
            dict.setDictDeleted(DictConstant.NO_DELETED);
            cmdbDictService.saveDict(dict);
//            CacheManager.syncDictToRedis(dict);
            result.put("status", 0);
            result.put("message", "修改成功");
        } catch (Exception e) {
            result.put("status", -1);
            result.put("message", "修改失败:" + e.getMessage());
        }
        return result;
    }

    @PostMapping("/create")
//    @RequiredPermission("/api/dict/create")
    @ApiOperation(value = "创建字典项信息", notes = "创建字典项信息")
    public Map<String, Object> saveDict(@RequestBody CmdbDict dict, HttpServletRequest request) {
        Map<String, Object> result = new HashMap<>();
        String dictName = dict.getDictName();
        if (null == dictName || (null != dictName && dictName.length() == 0)) {
            result.put("status", -1);
            result.put("message", "字典项名称不可以为空");
            return result;
        }
        CmdbDict checkTag1 = cmdbDictService.findByName(dictName);
        if (null != checkTag1 && !checkTag1.getDictId().equals(dict.getDictId())) {
            result.put("status", -1);
            result.put("message", "字典项名称已存在，不可以重复");
            return result;
        }
        String dictCode = dict.getDictCode();
        if (null != dictCode) {
            CmdbDict checkTag2 = cmdbDictService.findByDictCode(dictCode);
            if (null != checkTag2 && !checkTag2.getDictId().equals(dict.getDictId())) {
                result.put("status", -1);
                result.put("message", "字典项名称已存在，不可以重复");
                return result;
            }
        }

        try {
            List<CmdbDictValue> dictValues = dict.getDictValues();
            List<CmdbDictValue> dvs = new ArrayList<>();
            if (null != dictValues && dictValues.size() > 0) {
                for (CmdbDictValue dictValue : dictValues) {
                    CmdbDictValue dv = cmdbDictValueService.saveDictValue(dictValue);
                    dvs.add(dv);
                }
                dict.setDictValues(dvs);
            }
            dict.setDictDeleted(DictConstant.NO_DELETED);
            cmdbDictService.saveDict(dict);
//            CacheManager.syncDictToRedis(dict);
            result.put("status", 0);
            result.put("message", "创建成功");
        } catch (Exception e) {
            result.put("status", -1);
            result.put("message", "创建失败:" + e.getMessage());
        }

        return result;
    }

    @PostMapping("/delete")
//    @RequiredPermission("/api/dict/delete")
    @ApiOperation(value = "删除字典项信息", notes = "删除字典项信息")
    public Map<String, Object> deleteDict(@ApiParam(required = true, value = "字典项id") @RequestBody String jsonId) {
        Map<String, Object> result = new HashMap<>();
        Integer id = JsonTool.parseJsonIdStr(jsonId);
        if (id < 0) {
            result.put("status", -1);
            result.put("message", "id参数错误");
            return result;
        }
        CmdbDict dict = cmdbDictService.findById(id);
        Map<String, Object> param = new HashMap<>();
        param.put("EQ_dict.id", id);
// 仅经纪产品中心用到
//        List<CommonField> checkList1 = commonFieldService.findList(param);
//        if (null != checkList1 && checkList1.size() > 0) {
//            return ResultTool.fail(ResultTool.ErrorCode_2, "字典:" + dict.getDictName() + " 正在被公共字段使用,无法删除");
//        }
//        List<TemplateField> checkList2 = templateFieldService.findList(param);
//        if (null != checkList2 && checkList2.size() > 0) {
//            return ResultTool.fail(ResultTool.ErrorCode_2, "字典:" + dict.getDictName() + " 正在被模板字段使用,无法删除");
//        }
        dict.setDictDeleted(DictConstant.DELETED);
        cmdbDictService.saveDict(dict);
//        CacheManager.delDictInRedis(dict);
        result.put("status", 0);
        result.put("message", "删除成功");
        return result;
    }

    @PostMapping("/deleteids")
//    @RequiredPermission("/api/dict/deleteids")
    @ApiOperation(value = "批量删除字典项", notes = "批量删除字典项")
    public Map<String, Object> deleteDicts(@ApiParam(required = true, value = "产品id json字符串,支持多个 [{\"id\":1},{\"id\":2},...]")
                                           @RequestBody String jsonId) {
        Map<String, Object> result = new HashMap<>();
        List<Integer> ids = JsonTool.parseJsonIdsStrInteger(jsonId);
        if (null == ids) {
            result.put("status", -1);
            result.put("message", "id参数错误");
            return result;
        }
        if (null != ids && ids.size() > 0) {
            for (Integer id : ids) {
                CmdbDict dict = cmdbDictService.findById(id);
                if (null != dict) {
                    Map<String, Object> param = new HashMap<>();
                    param.put("EQ_dict.id", dict.getDictId());
//                    List<CommonField> checkList1 = commonFieldService.findList(param);
//                    if (null != checkList1 && checkList1.size() > 0) {
//                        return ResultTool.fail(ResultTool.ErrorCode_2, "字典:" + dict.getDictName() + " 正在被公共字段使用,无法删除");
//                    }
//                    List<TemplateField> checkList2 = templateFieldService.findList(param);
//                    if (null != checkList2 && checkList2.size() > 0) {
//                        return ResultTool.fail(ResultTool.ErrorCode_2, "字典:" + dict.getDictName() + " 正在被模板字段使用,无法删除");
//                    }
                    dict.setDictDeleted(DictConstant.DELETED);
                    cmdbDictService.saveDict(dict);
//                    CacheManager.delDictInRedis(dict);
                }
            }
            result.put("status", 0);
            result.put("message", "删除成功");
            return result;
        } else {
            result.put("status", -1);
            result.put("message", "没有有效id需要删除");
            return result;
        }

    }

    @GetMapping("/findbyid")
    @ApiOperation(value = "根据id查询字典项信息", notes = "根据id查询字典项信息")
    public Map<String, Object> findById(@ApiParam(required = true, value = "字典项id") @RequestParam String id,
                                        HttpServletRequest request) {

        Map<String, Object> result = new HashMap<>();
        try {
            CmdbDict dict = cmdbDictService.findById(Integer.parseInt(id));
            if (null != dict) {
                result.put("data", dict);
                result.put("message", "查询成功");
                result.put("status", 0);
            } else {
                result.put("status", -1);
            result.put("message", "没有查询到数据");
            return result;
            }

        } catch (Exception e) {
            logger.error("Error", e);
            result.put("message", "查询失败" + e.getMessage());
            result.put("status", -1);
        }

        return result;
    }

    @GetMapping("/findbyname")
    @ApiOperation(value = "根据名称查询字典项信息", notes = "根据名称查询字典项信息")
    public Map<String, Object> findByName(@ApiParam(required = true, value = "字典项名称") @RequestParam String dictName,
                                          HttpServletRequest request) {

        Map<String, Object> result = new HashMap<>();
        try {
            CmdbDict dict = cmdbDictService.findByName(dictName);
            if (null != dict) {
                result.put("data", dict);
                result.put("message", "查询成功");
                result.put("status", 0);
            } else {
                result.put("status", -1);
            result.put("message", "没有查询到数据");
            return result;
            }

        } catch (Exception e) {
            logger.error("Error", e);
            result.put("message", "查询失败" + e.getMessage());
            result.put("status", -1);
        }

        return result;
    }

    @GetMapping("/findbycode")
    @ApiOperation(value = "根据字典编码查询", notes = "根据字典编码查询")
    public Map<String, Object> findByCode(@ApiParam(required = true, value = "字典项编码") @RequestParam String dictCode,
                                          @ApiParam(required = false, value = "父级字典项的值") @RequestParam(value="parentValue", required = false) String parentValue,
                                          HttpServletRequest request) {

        Map<String, Object> result = new HashMap<>();
        try {
            CmdbDict dict = cmdbDictService.findByDictCode(dictCode);;
//            if (DictConstant.DICT_VM_PROD_LIST.equals(dictCode)) {
//                dict = dictService.findDictOfProdListVDict();
//            }else {
//                dict = CacheManager.getDictFromRedis(dictCode);
//            }
            if (null != dict) {
                if(parentValue!=null && parentValue.length() > 0){
                    List<CmdbDictValue> filterList = dict.getDictValues().stream().filter(item -> parentValue.equals(item.getParentValue())).collect(Collectors.toList());
                    dict.setDictValues(filterList);
                }
                result.put("data", dict);
                result.put("message", "查询成功");
                result.put("status", 0);
            } else {
                result.put("status", -1);
            result.put("message", "没有查询到数据");
            return result;
            }

        } catch (Exception e) {
            logger.error("Error", e);
            result.put("message", "查询失败" + e.getMessage());
            result.put("status", -1);
        }

        return result;
    }

    @GetMapping("/listbyname")
    @ApiOperation(value = "根据名称查询字典项列表", notes = "根据名称查询字典项列表")
    public Map<String, Object> listByName(@ApiParam(required = true, value = "字典项名称 模糊查询") @RequestParam String dictName,
                                          HttpServletRequest request) {

        Map<String, Object> result = new HashMap<>();
        try {
            Map<String, Object> param = new HashMap<>();
            param.put("LIKE_dictName", dictName);
            param.put("EQ_dictDeleted", 0);
            List<CmdbDict> list = cmdbDictService.findList(param);
            if (null != list && list.size() > 0) {
                result.put("data", list);
                result.put("total", list.size());
                result.put("message", "查询成功");
                result.put("status", 0);
            } else {
                result.put("status", -1);
            result.put("message", "没有查询到数据");
            return result;
            }

        } catch (Exception e) {
            logger.error("Error", e);
            result.put("message", "查询失败" + e.getMessage());
            result.put("status", -1);
        }

        return result;
    }


    @GetMapping("/list")
    @ApiOperation(value = "查询字典项列表", notes = "查询字典项列表")
    public Map<String, Object> findList(@ApiParam(required = false, value = "关键词") @RequestParam(required = false) String tag,
                                        HttpServletRequest request) {

        Map<String, Object> result = new HashMap<>();
        Map<String, Object> param = new HashMap<>();
        param.put("GT_dictId", 0);
        param.put("EQ_dictDeleted", 0);
        if (null != tag && tag.length() > 0) {
            param.put("LIKE_dictName", tag);
        }

        //用户权限
//        String userAccount = RequestTool.getAccountFromRequest();
//        User user = CacheManager.getUserFromRedis(userAccount);
//        List<Role> roles = user.getRoles();
//        Boolean isSysAdmin = false;//是否为系统管理员
//        Boolean isBizAdmin = false;//是否为
//
//        String dictCodes = "";
//        if (null != roles) {
//            for (Role role : roles) {
//                if (Constant.ROLE_BIZ_PARAMETER.equals(role.getRoleName())
//                        || Constant.ROLE_BIZ_PARAMETER_MARKET_UNIT.equals(role.getRoleName())
//                        || Constant.ROLE_BIZ_PARAMETER_PRODUCT_TYPE.equals(role.getRoleName())
//                ) {
//                    isBizAdmin = true;
//                    if (Constant.ROLE_BIZ_PARAMETER.equals(role.getRoleName())) {
//                        dictCodes = dictCodes + ",am_prod_property,am_prod_type,am_prod_invest_strategy,am_sz_trade_seat,am_sh_trade_seat,am_sh_clear_no";
//                    }
//                    if (Constant.ROLE_BIZ_PARAMETER_MARKET_UNIT.equals(role.getRoleName())) {
//                        dictCodes = dictCodes + ",am_sz_trade_seat,am_sh_trade_seat,am_sh_clear_no";
//                    }
//                    if (Constant.ROLE_BIZ_PARAMETER_PRODUCT_TYPE.equals(role.getRoleName())) {
//                        dictCodes = dictCodes + ",am_prod_property,am_prod_type,am_prod_invest_strategy";
//                    }
//                }
//                if (UserUtil.hasAdminRole(user)) {
//                    isSysAdmin = true;
//                }
//            }
//        }
//
//        if (isBizAdmin && !isSysAdmin) {//仅仅是业务管理员，那么只能维护业务管理员的字典项
//            if (dictCodes.startsWith(",")) {
//                dictCodes = dictCodes.substring(1);
//            }
//            logger.info(" user " + "," + user.getAccount() + ",query dictCodes=" + dictCodes);
////            dictCodes="am_prod_property,am_prod_type,am_prod_invest_strategy,am_sz_trade_seat,am_sh_trade_seat,am_sh_clear_no";
//            param.put("INSTR_dictCode", dictCodes);
////            资管产品性质	am_prod_property
////            资管产品类型	am_prod_type
////            资管投资策略	am_prod_invest_strategy
////            深圳交易单元	am_sz_trade_seat
////            上海交易单元	am_sh_trade_seat
////            上海清算编号	am_sh_clear_no
//        }
//        logger.info("dictCodes=" + dictCodes + ",isBizAdmin=" + isBizAdmin + ",isSysAdmin=" + isSysAdmin);

        List<CmdbDict> list = cmdbDictService.findList(param);
        if (null != list && list.size() > 0) {
            result.put("data", list);
            result.put("total", list.size());
            result.put("message", "查询成功");
            result.put("status", 0);
        } else {
            result.put("status", -1);
            result.put("message", "没有查询到数据");
            return result;
        }

        return result;
    }

    @GetMapping("/listpage")
    @ApiOperation(value = "查询字典项分页列表", notes = "查询字典项分页列表")
    public Map<String, Object> findListPage(@ApiParam(required = false, value = "字典名字，支持模糊搜索") @RequestParam(required = false) String dictName,
                                            @ApiParam(required = false, value = "字典编码，支持模糊搜索") @RequestParam(required = false) String dictCode,
                                            @ApiParam(required = false, value = "页码 1开始") @RequestParam(required = false) Integer pageNo,
                                            @ApiParam(required = false, value = "每页显示条数 默认10") @RequestParam(required = false) Integer pageSize,
                                            HttpServletRequest request) {

        Map<String, Object> result = new HashMap<>();
        Map<String, Object> param = new HashMap<>();
        pageNo = PageUtil.initPageNo(pageNo);
        pageSize = PageUtil.initPageSize(pageSize);

        param.put("GT_dictId", 0);
        param.put("EQ_dictDeleted", 0);
        if (StrUtil.isNotEmpty(dictName)) {
            param.put("LIKE_dictName", dictName);
        }
        if (StrUtil.isNotEmpty(dictCode)) {
            param.put("LIKE_dictCode", dictCode);
        }

        //用户权限
//        String userAccount = RequestTool.getAccountFromRequest();
//        User user = CacheManager.getUserFromRedis(userAccount);
//        List<Role> roles = user.getRoles();
//        Boolean isSysAdmin = false;//是否为系统管理员
//        Boolean isBizAdmin = false;//是否为
//        List<String> bizRole = new ArrayList<>();
//        if (null != roles) {
//            for (Role role : roles) {
//                if (Constant.ROLE_BIZ_PARAMETER.equals(role.getRoleName()) ||
//                        Constant.ROLE_BIZ_PARAMETER_MARKET_UNIT.equals(role.getRoleName()) ||
//                        Constant.ROLE_BIZ_PARAMETER_PRODUCT_TYPE.equals(role.getRoleName())) {
//                    isBizAdmin = true;
//                    logger.info("user " + userAccount + "拥有业务参数管理角色，" + role.getRoleName());
//                    bizRole.add(role.getRoleName());
//                }
//                if (UserUtil.hasAdminRole(user)) {
//                    isSysAdmin = true;
//                }
//            }
//        }
//        String dictCodes = null;
//        if (isBizAdmin && !isSysAdmin) {//仅仅是业务管理员，那么只能维护业务管理员的字典项
//            if (bizRole.contains(Constant.ROLE_BIZ_PARAMETER) || (bizRole.contains(Constant.ROLE_BIZ_PARAMETER_MARKET_UNIT) && bizRole.contains(Constant.ROLE_BIZ_PARAMETER_PRODUCT_TYPE))) {
//                dictCodes = "am_prod_property,am_prod_type,am_prod_invest_strategy,am_sz_trade_seat,am_sh_trade_seat,am_sh_clear_no";
//            } else if (bizRole.contains(Constant.ROLE_BIZ_PARAMETER_MARKET_UNIT)) {//交易单元管理
//                dictCodes = "am_sz_trade_seat,am_sh_trade_seat,am_sh_clear_no";
//            } else if (bizRole.contains(Constant.ROLE_BIZ_PARAMETER_PRODUCT_TYPE)) {//产品类型管理
//                dictCodes = "am_prod_property,am_prod_type,am_prod_invest_strategy";
//            }
//            param.put("INSTR_dictCode", dictCodes);
////            资管产品性质	am_prod_property
////            资管产品类型	am_prod_type
////            资管投资策略	am_prod_invest_strategy
////            深圳交易单元	am_sz_trade_seat
////            上海交易单元	am_sh_trade_seat
////            上海清算编号	am_sh_clear_no
//        }
//        logger.info("dictCodes=" + dictCodes + ",isBizAdmin=" + isBizAdmin + ",isSysAdmin=" + isSysAdmin + ",biz admin roles=" + bizRole.toString());

        Page<CmdbDict> list = cmdbDictService.findPage(pageNo, pageSize, param);
        if (null != list && list.getTotalElements() > 0) {
            result.put("data", list);
            result.put("message", "分页查询成功");
            result.put("status", 0);
        } else {
            result.put("status", -1);
            result.put("message", "没有查询到数据");
            return result;
        }

        return result;
    }

//    @GetMapping("/getcodetypedict")
//    @ApiOperation(value = "产品代码类型字典项值", notes = "产品代码类型字典项值")
//    public Map<String, Object> findProdCodeTypeDict(@ApiParam(required = true, value = "产品代码种类 1=公募基金 2=券商理财 z=其他理财") @RequestParam(required = true) String dictNameValue) {
//        if (StrUtil.isBlank(dictNameValue)) {
//            return Result.fail("字典项值必传");
//        }
//        CmdbDict dict = dictService.findByName("产品代码类型");
//        if (null == dict) {
//            return Result.fail(Result.CODE_ERROR_10002, "字典出错，请联系管理员");
//        }
//        Map<String, Object> result = new HashMap<>();
//        List<CmdbDictValue> list = new ArrayList<>();
//        String values = "";
//        if ("1".equals(dictNameValue)) {
//            //公募基金 1-9 a b m n r s t u v z J K L M N O P Q
//            values = "123456789abmnrstuvzJKLMNOPQ";
//        } else if ("2".equals(dictNameValue)) {
//            //券商理财 R S T c d w x y z
//            values = "RSTcdwxyz";
//        } else if ("z".equals(dictNameValue)) {
//            //其他理财： U V W X Y Z e f g h i j z
//            values = "UVWXYZefghijz";
//        } else {
//            return Result.fail(Result.CODE_ERROR_10002, "字典项值错误");
//        }
//        for (String value : values.split("")) {
//            CmdbDictValue dictValue = dictValueService.findByValueAndDictId(dict.getId(), value);
//            if (null != dictValue) {
//                list.add(dictValue);
//            }
//        }
//        result.put("status", 0);
//        result.put("message", "数据获取成功");
//        result.put("data", list);
//        return result;
//
//    }

    @GetMapping("/findbyparentcode")
    @ApiOperation(value = "根据父code查询子字典项信息", notes = "根据父code查询子字典项信息")
    public Map<String, Object> findByParentCode(@ApiParam(required = true, value = "字典项code") @RequestParam String parentCode,
                                                HttpServletRequest request) {

        Map<String, Object> result = new HashMap<>();
        try {
            List<CmdbDict> dictList = cmdbDictService.findByParentCode(parentCode);
            if (null != dictList) {
                result.put("data", dictList);
                result.put("message", "查询成功");
                result.put("status", 0);
            } else {
                result.put("status", -1);
                result.put("message", "没有查询到数据");
                return result;
            }

        } catch (Exception e) {
            logger.error("Error", e);
            result.put("message", "查询失败" + e.getMessage());
            result.put("status", -1);
        }

        return result;
    }

//    @GetMapping("/findallproductdictValues")
//    @ApiOperation(value = "查询产品中用到的所有字典信息", notes = "查询产品中用到的所有字典信息")
//    public Result<Map<String, Map<String, String>>> findAllProductDictValues(@ApiParam(value = "是否转换value和label") @RequestParam(value = "revert", required = false) String revert) {
//        try {
//            Map<String, Map<String, String>> resultData = dictService.findByDictCodeList(Arrays.asList(DictConstant.ALL_DICT_CODE_LIST), DictConstant.NO);
//            return Result.successData(resultData);
//        } catch (Exception e) {
//            logger.error("Error", e);
//            return Result.failData("查询失败");
//        }
//    }

//    @GetMapping("/findByDictCodeList")
//    @ApiOperation(value = "根据字典编码列表查询字典", notes = "根据字典编码列表查询，注意传参数时URL长度限制")
//    public Result<Map<String, Map<String, String>>> findByDictCodeList(@ApiParam(required = false, value = "字典项编码列表") @RequestParam(name = "dictCodeList", required = false) List<String> dictCodeList) {
//
//        try {
//            Map<String, Map<String, String>> resultData = dictService.findByDictCodeList(dictCodeList, DictConstant.NO);
//            return Result.successData(resultData);
//        } catch (Exception e) {
//            logger.error("Error", e);
//            return Result.failData("查询失败");
//        }
//    }

    @GetMapping("/findByConfigCode")
    @ApiOperation(value = "根据系统配置查询字典项信息", notes = "根据系统配置查询字典项信息")
    public Map<String, Object> findByConfigCode(@ApiParam(required = true, value = "字典项编码") @RequestParam String dictCode,
                                                @ApiParam(required = true, value = "系统配置项") @RequestParam String configCode) {

        Map<String, Object> result = new HashMap<>();
        try {
            CmdbDict dict = cmdbDictService.findByConfigCode(dictCode, configCode);
            if (null != dict) {
                result.put("data", dict);
                result.put("message", "查询成功");
                result.put("status", 0);
            } else {
                result.put("status", -1);
                result.put("message", "没有查询到数据");
                return result;
            }

        } catch (Exception e) {
            logger.error("Error", e);
            result.put("message", "查询失败" + e.getMessage());
            result.put("status", -1);
        }

        return result;
    }
}